function init() 
{								
	var params = {};
	params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] =
	[
		opensocial.Person.Field.NICKNAME, 
		opensocial.Person.Field.THUMBNAIL_URL,
		opensocial.Person.Field.PROFILE_URL,
		opensocial.Person.Field.ADDRESSES,
		opensocial.Person.Field.GENDER,
		opensocial.Person.Field.AGE,
		opensocial.Person.Field.DATE_OF_BIRTH,
		opensocial.Person.Field.INTERESTS,
		opensocial.Person.Field.HAS_APP,
		mbga.Person.Field.JOB_TYPE,
		mbga.Person.Field.BLOOD_TYPE
	];
	
	var req = opensocial.newDataRequest();
	var obj;
	req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER, params), "viewer");
	
	req.send(callback);             
	/*
	//document.getElementById("kvtm").src=
		//"http://kvtm.apps.zing.vn/celestial/index.php?params=&session_id="+m_snsses+"&sign_user="+m_snsuid+"&username="+user_name;
		//"http://kvtm.apps.zing.vn/celestial/ymbgapi/listFriends.php";
		//"http://kvtm.apps.zing.vn/celestial/ymbgapi/Ymbg.php";
	
	var params = {
					width:  "836",
					height: "622",
					wmode: "opaque",
					id: "KVTM_flash",
					name: "KVTM_flash",
					menu: "false",
					allowFullScreen: "true",
					scale: "noscale",
					allowScriptAccess: "always",
					sign_user:"19894710",
					session_id:"1F0189882566C0C43B274934",
					username:"nhnpro"
				};											
		
	gadgets.flash.embedFlash(
	"http://update.game.zing.vn/firebat/celestial/v060/CelestialGarden_0.6.0a.swf", 
	document.getElementById("flash"),
	6,
	params
	);
		
			
	var params2 = {
		menu: "false",
		wmode: "opaque",
		allowFullScreen: "true",
		scale: "noscale",
		allowScriptAccess: "always",
		bgcolor: "#FFFFFF"
	};
	var attributes = {
		id: "Skygarden",
		name: "Skygarden"
	};							
	var flashVars = {};
	flashVars["sign_user"] = "19894710";
	flashVars["session_id"] = "1F0189882566C0C43B274934";
	flashVars["username"] = "nhnpro";
	
	swfobject.embedSWF(
		'http://update.game.zing.vn/firebat/celestial/v060/CelestialGarden_0.6.0a.swf',
		'Skygarden', "836", "622",
		'10.0.0', 'expressInstall.swf',
		flashVars, params2, attributes);
	gadgets.window.adjustHeight();
*/				
}

function callback(response)
{
	if( response.hadError() )
	{
		// error
		//thisFlash("externalanimal").SendYMBG(-1);
		document.getElementById("header").innerHTML = "err0";
	}
	else
	{
		var item = response.get("viewer");
		var viewer = item.getData();
		
		if( item.hadError() )
		{
			// error
			//thisFlash("externalanimal").SendYMBG(-1);
			document.getElementById("header").innerHTML = "err1";
		}
		else
		{
			try
			{
				var m_snsuid;// = "19894710";
				var m_snsses; //= "1F0189882566C0C43B274934";
				var user_name;// = "nhnpro";   
				
				if(viewer.isViewer()&&viewer.isOwner())
				{
					user_name = viewer.getDisplayName(); 
					m_snsuid = viewer.getId().split(":")[1];
					m_snsses = creatSessionID(shindig.auth.getSecurityToken(),24);
				
					document.getElementById("header").innerHTML = "<b>ID = </b>" + viewer.getId() 
																	+" || <b>Display Name = </b>" + viewer.getDisplayName()
																	+" || <b>NickName = </b>" + viewer.getField(opensocial.Person.Field.NICKNAME)
																	+" || <b>Gender = </b>" + viewer.getField(opensocial.Person.Field.GENDER).getDisplayValue()
																	+" || <b>isViewer = </b>" + viewer.isViewer() 
																	+" || <b>isOwner = </b>" + viewer.isOwner();
																	
					document.getElementById("footer1").innerHTML = "<b>AvatarURL = </b>" +  viewer.getField(opensocial.Person.Field.THUMBNAIL_URL)
																	+" || <b>Session_id = </b>" + m_snsses;							
					document.getElementById("footer2").innerHTML = "<b>SecurityToken = </b>" + shindig.auth.getSecurityToken();
					//document.getElementById("footer3").innerHTML = "";
					
					document.getElementById("kvtm").src= 
						"http://kvtm.apps.zing.vn/celestial/index.php?params=&"
																+ "session_id=" + m_snsses
																+ "&sign_user=" + m_snsuid
																+ "&username="  + user_name;
				}																
				
				//thisFlash("externalanimal").SendYMBG(1);
				//thisFlash("externalanimal").JsToSetInfo(new UserInfo(
				
											// viewer.getId(),
											// viewer.getField(opensocial.Person.Field.NICKNAME), 
											// viewer.getField(opensocial.Person.Field.THUMBNAIL_URL),
											// viewer.getField(opensocial.Person.Field.PROFILE_URL),
											// viewer.getField(opensocial.Person.Field.ADDRESSES)[0].getField(opensocial.Address.Field.REGION),
											// viewer.getField(opensocial.Person.Field.PROFILE_URL),
											// viewer.getField(opensocial.Person.Field.GENDER).getDisplayValue(),
											// viewer.getField(opensocial.Person.Field.AGE),
											// viewer.getField(opensocial.Person.Field.DATE_OF_BIRTH),
											// viewer.getField(opensocial.Person.Field.INTERESTS),
											// viewer.getField(mbga.Person.Field.JOB_TYPE),
											// viewer.getField(mbga.Person.Field.BLOOD_TYPE),
											// viewer.getField(opensocial.Person.Field.HAS_APP)));
			}
			catch(e) {}
		}
	}
	
	gadgets.window.adjustHeight();
}
function creatSessionID(sChrs,len)
{
	var iChars = "!@#$%^&*()+=-[]\';,./{}|\":<>?";   
	//session_id = security_token.substr(0,24);
	var sRnd = '';
	for (var i=0; i<len; i++)
	{
		var randomPoz = Math.floor(Math.random() * sChrs.length);
		if((sChrs.charAt(randomPoz)>='a' && sChrs.charAt(randomPoz)<='z')
		  ||(sChrs.charAt(randomPoz)>='A' && sChrs.charAt(randomPoz)<='Z')
		  ||(sChrs.charAt(randomPoz)>='0' && sChrs.charAt(randomPoz)<='9'))			
			sRnd += sChrs.substring(randomPoz,randomPoz+1);
		else
			sRnd += Math.floor(Math.random() * 'Z') +'A';
	}
	return sRnd;
}

gadgets.util.registerOnLoadHandler(init);